<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" session="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <title>应用管理</title>

    <link href="${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/css/bootstrap.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/font-awesome-4.3.0/css/font-awesome.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/css/select2.min.css"
          rel="stylesheet">
    <!-- jqgrid-->
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/custom.ui.jqgrid.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/layer/skin/layer.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/style.css" rel="stylesheet">

    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/jquery.form.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/common.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/i18n/grid.locale-cn.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/minified/jquery.jqGrid.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/layer/layer.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/static/js/global.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/js/select2.min.js"></script>
	<script type="text/javascript"
            src="${pageContext.request.contextPath}/static/plugins/My97DatePicker/WdatePicker.js"></script>
    <style type="text/css">
        .main h5 a {
            position: absolute;
            right: 20px;
            font-size: 14px;
            bottom: 0px;
            display: inline-block;
            padding: 5px;
        }

        .table_list tbody tr {
            height: 35px;
            text-align: center;
        }
		.left ul li{
			
			*line-height:40px;
			
			*padding-left:20px;
		}
		
		.left ul li a, .left ul li a:hover{
			*color:#fff;
		}
		.list-tab li{
			*+padding:0px 10px 10px;
		}
		.wrapper{
			*margin-left:270px;
		}
		.btn{
			*width:120px;
		}
		.col-sm-1{width:20%;*+width:16%;}
		.lt{
			float:left;
		}
		.ui-pg-button{
			*background:#ccc;
		}
		.col-md-3{width:270px\9;}
		#type,.select2-selection {
			*+width:150px;
		}
		#ptime1,#appName{
			width:190px\9;
			*width:150px;
		}
		
		.form-control{
			*padding:0;
			*+width:120px;
		}
		.form-group{
			*overflow: hidden;
		}
		.btn-success {
			*width:60px;
		}
		.form-lable{width:100px\9;width:90px !important;*+width:60px !important;}
    </style>
</head>
<body view="menu-item-4142">
<jsp:include page="../../top.jsp"></jsp:include>
<div class="right">
 	<div class="wrapper">
        <div class="panel panel-default">
            <div class="panel-heading">
                <span><strong>查询条件</strong></span>

                <div class="ibox-tools">
                    <a class="collapse-link"> <i class="fa fa-chevron-down"></i></a>
                    <a class="collapse-link  d-n"> <i class="fa fa-chevron-up"></i></a>
                </div>
            </div>
            <div class="panel-body">
            	<c:if test="${userRole == 1 || userRole == 2}">
	                <form class="form-horizontal">
	                    <div class="form-group">
	                        <label class="form-lable lt" >公司名称：</label>
	                        <div class="col-md-3 lt">
	                            <select name="agtCode" id="agtCode" class="form-control lt"></select>
	                        </div>
	                        
	                        <label class="form-lable lt">应用名称：</label>
	                        <div class="col-md-3 lt"  >
	                            <input id="appName" name="appName" type="text" class="form-control lt"/>
	                        </div>
	                      </div> 
	                      <div class="form-group">
	                       <label class="form-lable lt">类&nbsp;&nbsp;型：</label>
	                        <div class="col-md-3 lt" >
	                            <select name="type" id="type" class="form-control lt">
	                                <option value="">请选择类型</option>
	                                <option value="0">上架</option>
	                                <option value="1">下架</option>
	                            </select>
	                        </div>
	                        
	                      	<label class="form-lable lt">日期：</label>
	                        <div class="col-sm-3 lt">
	                                <input class="form-control" name="ptime1" id='ptime1'
	                                       onclick='WdatePicker()'/>
	                        </div>
		                        
	                        <div class="col-md-1 lt form-action">
	                            <button class="btn btn-success form-control" id="query">查询</button>
	                        </div>
	                        <div class="col-md-1 lt form-action">
	                            <button class="btn btn-success form-control" id="resetForm">清空</button>
	                        </div>
	                    </div>
	                </form>
                </c:if>
                <c:if test="${userRole == 3 || userRole == 4}">
                	<form class="form-horizontal">
	                    <div class="form-group">
	                        <label class="selectlabe1 col-md-1 lt form-lable" >公司名称：</label>
	                        <div class="col-md-2 lt">
	                            <select name="agtCode" id="agtCode" class="form-control"></select>
	                        </div>
	                        
	                       <label class="selectlabe1 col-md-1 form-lable lt">类&nbsp;&nbsp;型：</label>
	                        <div class="col-md-2 lt" >
	                            <select name="type" id="type" class="form-control lt">
	                                <option value="">请选择类型</option>
	                                <option value="0">上架</option>
	                                <option value="1">下架</option>
	                            </select>
	                        </div>
	                        
	                      	<label class="selectlabe1 col-md-1 lt form-lable">日期：</label>
	                        <div class="col-sm-1 lt">
	                                <input class="form-control" name="ptime1" id='ptime1'
	                                       onclick='WdatePicker()'/>
	                        </div>
		                        
	                        <div class="col-md-1 form-action lt">
	                            <button class="btn btn-success form-control" id="query">查询</button>
	                        </div>
	                        <div class="col-md-1 lt form-action">
	                            <button class="btn btn-success form-control" id="resetForm">清空</button>
	                        </div>
	                    </div>
	                </form>
                </c:if>
            </div>
        </div>
        
	    <div class="jqGrid_wrapper">
	        <div id="jqGrid_operation" class="jg-grid">
	            <h1>应用管理</h1>
	            <div class="jqGrid_operation" id="action"></div>
	        </div>
	        <table id="jqGrid"></table>
	        <div id="jqGrid_paper"></div>
	    </div>
	</div>

</div>
<script>
var act="${act}";
    $(document).ready(
            function () {
                $.ajax({
                    type: "POST",
                    async: false,
                    url: '/admin/auth_buttons.action',
                    data: "url=" + window.location.pathname,
                    success: function (data) {
                        data = eval("(" + data + ")");
                        for (var i in data) {
                            var action = data[i].mName;
                           	if(act=='1'){
                           		switch (action) {
	                            	case "应用新增":
	                                    $("#action").append("<a id=\"add\"><i class=\"glyphicon glyphicon-plus\"></i>添加</a>");
	                                    break;
	                                case "应用修改":
	                                    $("#action").append("<a id=\"edit\"><i class=\"glyphicon glyphicon-edit\"></i>修改</a>");
	                                    break;
	                                case "应用设置":
	                                    $("#action").append("<a id=\"set\"><i class=\"glyphicon glyphicon-edit\"></i>设置</a>");
	                                    break;
                           		}
                               
                           	}else if(act=='2'){
                             	switch (action) {
  	                            	case "编辑关于我们":
  	                                    $("#action").append("<a id=\"aboutUs\"><i class=\"glyphicon glyphicon-edit\"></i>修改</a>");
                             	}
                           	}else if(act=='3'){
                             	switch (action) {
	                            	case "编辑用户协议":
	                                    $("#action").append("<a id=\"userProtocol\"><i class=\"glyphicon glyphicon-edit\"></i>修改</a>");
                             	}
                         	}
                       	}
                   	 }
                });
                

                $.jgrid.defaults.styleUI = "Bootstrap";
                $("#jqGrid").jqGrid(
                        {
                            url: "${pageContext.request.contextPath}/admin/appstore_page.action",
                            mtype: 'POST',
                            datatype: "json",
                            height: 360,
                            autowidth: true,
                            shrinkToFit: true,
                            rowNum: 10,
                            rowList: [10, 20, 30],
                            colNames: ['序号', '应用ID', '公司', '类型', '应用名称','创建时间 '],
                            colModel: [{
                                name: "SID",
                                index: "SID",
                                key: true,
                                hidden: true
                            }, {
                                name: 'APPID',
                                index: 'APPID',
                                width: 90
                            }, {
                                name: 'AGTCODE',
                                index: 'AGTCODE',
                                width: 80
                            },{
                                name: 'APPTYPE',
                                index: 'APPTYPE',
                                width: 80,
                                formatter: "select", 
                                editoptions:{value:"-1:;0:上架;1:下架"}
                            },{
                                name: 'APPNAME',
                                index: 'APPNAME',
                                width: 80
                            }, {
                                name: "CTIME",
                                index: "CTIME",
                                width: 80
                            }],
                            sortname: 'sid',
                            sortorder:'desc',
                            rownumbers: true,
                            jsonReader: {
                                root: 'rows',
                                page: "page",
                                total: 'total',
                                records: "records",
                                repeatitems: false
                            },
                            pager: "#jqGrid_paper",
                            viewrecords: true,
                            multiselect: true,
                            hidegrid: false,
                            loadComplete: function(){
                        		var re_records = Number($("#jqGrid").getGridParam('records'));
                        		var page = Number($("#jqGrid").getGridParam('page'));
                        		var rows=Number($("#jqGrid").getGridParam('rowNum'));
                        		var num = re_records-(page-1)*rows;
                        		if(num < rows)
                        		{
                        			for(var i=num;i<rows;i++){
                        				$("#jqGrid").jqGrid("addRowData",(i+1),
                                				{ "SID":"", "APPID":"", "AGTNAME":"", "APPTYPE":"", "select":"-1","APPNAME":"","CTIME":""}
                        				,"");
                        			}
                        			$(".ui-paging-info").html(re_records-num+1 +" - "+re_records+"　共 "+re_records+" 条");
                        		}
                        	}
                        });
                $.post("${pageContext.request.contextPath}/admin/tagent_list.action", function (data) {
		            $("#agtCode").empty();
		            $("#agtCode").append("<option value=''>请选择公司</option>");
		            for (var i = 0; i < data.length; i++) {
		                $("#agtCode").append("<option value='" + data[i].agtCode + "'>" + data[i].agtName + "</option>");
		            }
		            $("#agtCode").select2({
		                "placeholder": "请选择公司",
		                "width": "100%"
		            })
		        }, "json");
                <!--查询-->
                jQuery("#query").click(query);
                jQuery("#resetForm").click(resetForm);
                
                $("#add").click(function () {
                    layer.open({
                        type: 2,
                        title: ['应用新增', 'font-weight:bold'],
                        shadeClose: true, //点击遮罩关闭层
                        area: ['800px', '700px'],
                        scrollbar: false,
                        content: '${pageContext.request.contextPath}/admin/appstore_addView.action',
                        btn: ['提交', '取消'],
                        yes: function (index, layero) {
           	            	$("#layui-layer-iframe" + index).contents().find("#sure").html("again");
           	            	$("#layui-layer-iframe" + index).contents().find("#sure").click();
           	            	var options = {
           	                    success: function (data) {
           	                        data = JSON.parse(data);
           	                        if (data.code == 1) {
           	                            layer.alert(data.msg, function () {
           	                                layer.closeAll();
           	                                refreshGrid();
           	                            });
           	                        } else {
           	                            layer.alert(data.msg);
           	                        }
           	                    }
           	                };
                        	
                        },
                        cancel: function (index, layero) {
                            layer.close(index);
                        }
                    });
                });
                
                $("#edit").click(function () {
                    var sels = jQuery("#jqGrid").jqGrid('getGridParam', 'selarrrow');
                    if (sels.length == 1) {
                    	 layer.open({
                             type: 2,
                             title: '<strong>应用修改</strong>',
                             shadeClose: true, //点击遮罩关闭层
                             area: ['800px', '700px'],
                             content: '${pageContext.request.contextPath}/admin/appstore_editView.action?sid='
                             + sels.toString(),
                             btn: ['提交', '取消'],
                             yes: function (index, layero) {
                           		$("#layui-layer-iframe" + index).contents().find("#sure").html("again");
                  	            $("#layui-layer-iframe" + index).contents().find("#sure").click();
                             }
                         });
                    } else {
                        layer.alert("请选择记录且只能1条记录", {
                            icon: 6,
                            closeBtn: false
                        });
                    }
                });
                
                $("#set").click(function () {
                    var sels = jQuery("#jqGrid").jqGrid('getGridParam', 'selarrrow');
                    if (sels.length == 1) {
                    	 layer.open({
                             type: 2,
                             title: '<strong>应用修改</strong>',
                             shadeClose: true, //点击遮罩关闭层
                             area: ['800px', '500px'],
                             content: '${pageContext.request.contextPath}/admin/appstore_setView.action?sid='
                             + sels.toString(),
                             btn: ['提交', '取消'],
                             yes: function (index, layero) {
                           		$("#layui-layer-iframe" + index).contents().find("#sure").html("again");
                  	            $("#layui-layer-iframe" + index).contents().find("#sure").click();
                             }
                         });
                    } else {
                        layer.alert("请选择记录且只能1条记录", {
                            icon: 6,
                            closeBtn: false
                        });
                    }
                });
                
                $("#aboutUs").click(function () {
                    var sels = jQuery("#jqGrid").jqGrid('getGridParam', 'selarrrow');
                    if (sels.length == 1) {
                    	var rowData = $("#jqGrid").jqGrid('getRowData',sels.toString());
                    	 layer.open({
                             type: 2,
                             title: '<strong>修改关于我们>'+rowData.APPNAME+'</strong>',
                             shadeClose: true, //点击遮罩关闭层
                             area: ['800px', '400px'],
                             content: '${pageContext.request.contextPath}/admin/appstore_aboutUsView.action?sid='
                             + sels.toString(),
                             btn: ['提交', '取消'],
                             yes: function (index, layero) {
                           		$("#layui-layer-iframe" + index).contents().find("#sure").html("again");
                  	            $("#layui-layer-iframe" + index).contents().find("#sure").click();
                             }
                         });
                    } else {
                        layer.alert("请选择记录且只能1条记录", {
                            icon: 6,
                            closeBtn: false
                        });
                    }
                });
                
                $("#userProtocol").click(function () {
                    var sels = jQuery("#jqGrid").jqGrid('getGridParam', 'selarrrow');
                    if (sels.length == 1) {
                    	window.location='${pageContext.request.contextPath}/admin/appstore_userProtocolView.action?sid='+ sels.toString();
                    } else {
                        layer.alert("请选择记录且只能1条记录", {
                            icon: 6,
                            closeBtn: false
                        });
                    }
                });
                
            });
    $("#type").select2({
        "placeholder": "请选择类型",
        "minimumResultsForSearch":-1
    })
    <!--刷新jqGrid表格数据-->
    function refreshGrid() {
        $("#jqGrid").trigger("reloadGrid");
    }
    function resetForm() {
        location.reload();
        return false;
    }
    function query() {
        var $agtCode = $("#agtCode").val();
        var $ptime1 = $("#ptime1").val();
        var $appName = $("#appName").val();
        var $type = $("#type").val();
        $("#jqGrid").jqGrid('setGridParam', {
            url: "${pageContext.request.contextPath}/admin/appstore_page.action",
            postData: {
                'agtCode': $agtCode,
                'appName': $appName,
                'type': $type,
                'ptime1': $ptime1
            }, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入*/
        return false;
    };
	
</script>
</body>
</html>
